package com.pxx.item.controller;

import com.pxx.item.pojo.TbSku;
import com.pxx.item.pojo.TbSpu;
import com.pxx.item.service.TbSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : Yoo19
 * @description :
 * @createDate : 2025/6/27 19:52 52
 */
@RestController
@RequestMapping("/item/sku")
public class SkuController {
    @Autowired
    private TbSkuService tbSkuService;

    /**
     * 根据Id查询对应的sku数据
     * @param spuId
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<TbSku>> querySkuListBySpuId(@RequestParam("id")Long id){
      List<TbSku> skuList =  tbSkuService.querySkuListBySpuId(id);
      if(CollectionUtils.isEmpty(skuList)){
          return ResponseEntity.notFound().build();
      }

      return ResponseEntity.ok(skuList);
    }
}
